﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using JY.Common.Enums;
using JY.IOC;
using JY.Wpf.Core.Enums;
using JY.Wpf.Core.Tools;
using JY.Wpf.Core.ViewModelBases;
using JY.Wpf.TestClient.Views;

namespace JY.Wpf.TestClient.ViewModels
{
    public class TestWindowViewModel : WindowViewModelBase
    {
        public TestWindowViewModel()
        {
            IsDialog = true;
            this.WindowState = WindowState.Maximized;
        }

        #region # 繁忙状态操作——void BusyOperation()
        /// <summary>
        /// 繁忙状态操作
        /// </summary>
        public override void BusyOperation()
        {
            Wpf.Controls.Controls.BusyIndicator.BusyOperation(this.IsBusy, this.BusyContent);
        }

        #endregion

        #region # 完成警告消息回调方法——void DeactivateMessage()
        /// <summary>
        /// 完成警告消息回调方法
        /// </summary>
        private void DeactivateMessage(MessageType messageType)
        {
            //MessageBox.Info($"测试完成警告消息[{messageType}]回调方法。");
        }
        #endregion
        public async void TestBusy()
        {
            this.Busy();
            await Task.Delay(3000);
            this.Idle();
        }
        public void TestMessage()
        {
            this.ShowWarningMessage("测试消息");
        }

        protected override void OnViewLoaded(object view)
        {
            base.OnViewLoaded(view);

            Wpf.Controls.Controls.WarningMessageBar.Initialize(this.DeactivateMessage);
        }

        public override void WindowClosing(CancelEventArgs args)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show($"当前正在配置轨迹！可能存在未保存数据！是否关闭窗体？", "提示信息", MessageBoxButton.YesNo);
            args.Cancel = messageBoxResult != MessageBoxResult.Yes;
        }

        #region 获取页面——object GetView(object context = null)

        /// <summary>
        /// 获取页面
        /// </summary>
        /// <param name="context">页面</param>
        /// <returns></returns>
        public override object GetView(object context = null)
        {
            return this.View ?? ResolveMediator.Resolve<TestWindowView>();
        }

        #endregion
    }
}
